# _*_ coding: utf-8 _*_
from odoo import models, api, fields, _
from odoo.exceptions import Warning


class OLProductProductExtend(models.Model):
    _inherit = "product.product"

    eliminate = fields.Boolean('Eliminate', default=False)
    not_eliminate = fields.Boolean('Not Eliminate', default=True)
    eliminate_date = fields.Date('Eliminate Date')

    @api.multi
    def toggle_eliminate(self):
        for record in self:
            record.eliminate = not record.eliminate
            record.not_eliminate = not record.eliminate
            quants = self.env['stock.quant'].search([('product_id', '=', self.id)])
            quants.write({'eliminate': record.eliminate})

            so_lines = self.env['sale.order.line'].search([('product_id', '=', self.id)])
            so_lines.write({'eliminate': record.eliminate})
            if record.eliminate:
                record.message_post(_('From Normal change to Eliminate'))
                record.eliminate_date = fields.Date.today()
            else:
                record.message_post(_('From Eliminate change to Normal'))
                record.eliminate_date = False
